package com.example.spring.mapper;

import com.example.spring.entity.Worker;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WorkerMapper {
    //查询所有
    @Select("SELECT * FROM worker")
    List<Worker> findAll();
    //插入
    @Insert("INSERT INTO worker(whid, password, username,  name, address, tel, salary) VALUES(#{whid}, " +
            "AES_ENCRYPT(#{password},'MySQL'), " +
            "#{username}, #{name}, #{address},#{tel}, #{salary})")
    int insert_data(Worker worker);
    //更新（动态sql）
    int update(Worker worker);
    //按id删除
    @Delete("DELETE FROM worker WHERE wkid = #{wkid}")
    Integer deleteById(@Param("wkid") Integer wkid);

    //查询指定username的员工
    @Select("SELECT * FROM worker WHERE username = #{username}")
    Worker find_by_username(@Param("username") String username);

//    @Select("SELECT * FROM worker WHERE wkid = #{wkid}")
//    Worker find_by_wkid(@Param("wkid") String wkid);

    //查询指定id用户
    @Select("SELECT * FROM worker WHERE wkid = #{wkid}")
    Worker find_by_wkid(@Param("wkid") Integer wkid);

    //查询合法用户
    @Select("SELECT * FROM worker WHERE username = #{username}")
    List<Worker> valid_worker(@Param("username") String username);
    //确定用户名和密码是否匹配
    @Select("SELECT * FROM worker WHERE username = #{username} AND password = AES_ENCRYPT(#{password},'MySQL')")
    List<Worker> valid_match_password(@Param("username") String username, @Param("password") String password);
    //分页查询
    @Select("SELECT * FROM worker LIMIT #{pageNum}, #{pageSize}")
    List<Worker> selectPage(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);
    //查询员工总数
    @Select("SELECT count(*) FROM worker")
    Integer selectTotal();
    //查询用户名姓名电话等于特定值的用户
    @Select("SELECT * FROM worker WHERE username = #{username} AND name = #{name} AND tel = #{tel}")
    List<Worker> forgetPassword(@Param("username") String username, @Param("name") String name, @Param("tel") String tel);

}
